class Solution {
public:
    string addStrings(string num1, string num2) {
        int end1 = num1.size() - 1;
        int end2 = num2.size() - 1;
        string AddNum;
        AddNum.reserve(max(num1.size(), num2.size()) + 1);
        int next = 0;
        char ch;
        while (end1 >= 0 || end2 >= 0)
        {
            int x1 = end1 >= 0 ? num1[end1] - '0' : 0;
            int x2 = end2 >= 0 ? num2[end2] - '0' : 0;
            int sum = x1 + x2 + next;
            next = sum / 10;
            ch = '0' + sum % 10;
            AddNum.push_back(ch);
            end1--;
            end2--;
        }
        if (next == 1)
        {
            AddNum.push_back('1');
        }
        reverse(AddNum.begin(), AddNum.end());
        return AddNum;
    }
};